<template>
    <div>
            <Card>
                <p slot="title">
				    修改基础数据
			    </p>
                <div>
                    <Form class="step-form" ref="basicDataList" :model="basicDataList" :rules="basicDataRules" :label-width="100">
                        <Row span="12">
                            <i-col span="6" >
                                <FormItem label="类型名称：" label-position="left" :label-width="150">
                                    <Input disabled v-model="basicDataList.typeName" type="text" placeholder="请输入类型名称" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="6" >
                                <FormItem label="字典代码："  prop="dataCode" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="basicDataList.dataCode" type="text" placeholder="请输入类型数据" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="6" >
                                <FormItem label="字典数据："  prop="dataValue" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="basicDataList.dataValue" type="text" placeholder="请输入类型数据" />
                                </FormItem>
                            </i-col>
                        </Row>

                        <FormItem >
                            <Button :disabled="hasSubmit" @click="handleSubmit" style="width:100px;" type="primary">提交</Button>
                        </FormItem>
                    </Form>
                </div>
            </Card>
    </div>
</template>

<script>
import ajax from '../../../../libs/axios.js'
export default {
    name: 'updateBasicData',
    data () {
        return {
            basicDataList: {
                id:'',
                /**数据类型的id*/
                typeId:'',
                /**数据类型的name*/
                typeName:'',
                /**字典代码*/
                dataCode:'',
                /**字典数据*/
                dataValue:'',
                userId: '',
                userName: '',
                queryType:'' // 用于区分是type表 还是data表
            },
            basicDataRules: {
                dataCode: [
                    { required: true, message: '请输入类型数据', trigger: 'blur'},
                    {type: 'string', max: 500, message: '不能超过500个字符', trigger: 'blur'}
                ],
                dataValue: [
                    { required: true, message: '请输入类型数据', trigger: 'blur'},
                    {type: 'string', max: 500, message: '不能超过500个字符', trigger: 'blur'}
                ],
            },
            hasSubmit: false,
            status: 'wait'
        }
    },
    methods: {
        // 数据初始化
        init () {
            let id = this.$route.params.id
            let typeId = this.$route.params.typeId
            let queryType = this.$route.params.queryType
            this.basicDataList.queryType = queryType
            console.log("获取到传过来的id:" + id)
            console.log("获取到传过来的typeId:" + typeId)
            console.log("获取到传过来的queryType:" + queryType)
            this.getData(id)
        },
        handleSubmit () {
            this.basicDataList.userId = window.localStorage.getItem('userId')
            this.basicDataList.userName = window.localStorage.getItem('userName')

            this.$refs['basicDataList'].validate((valid) => {
                if (valid) {
                    this.hasSubmit = true
                    let url = '/adminapi/basicdata/updateData.html'
                    let data = this.basicDataList
                    console.log('-----------------data---------------------')
                    console.log(data)
                    ajax.formRes(url, data).then(res => {
                        this.$Message.success('更新数据成功,页面正在跳转')
                        let vm = this
                        setTimeout(function () {
                            vm.hasSubmit = false
                            let typeId = vm.basicDataList.typeId
                            let argu = {
                                id: typeId,
                                queryType:vm.basicDataList.queryType
                            }
                            vm.$router.push({
                                name: 'basicdataindex',
                                params: argu
                            })
                        }, 1500)

                    }).catch(res => {
                        console.log('有错误信息')
                    })
                } else {
                    console.log('更新数据失败。。。')
                }
            })
        },
        getData(id){
            let url = '/adminapi/basicdata/getUpdateData.html'
            let data = {
                id: id
            }
            ajax.formRes(url, data).then(res => {
                // success
                console.log('******************')
                console.log(res)
                let vm = this
                vm.basicDataList.id = res.id
                vm.basicDataList.typeId = res.typeId
                vm.basicDataList.typeName = res.typeName
                vm.basicDataList.dataCode = res.dataCode
                vm.basicDataList.dataValue = res.dataValue
            }).catch(res => {
                console.log('获取基础数据有错误信息')
                // fail
            })
        },
        emptyData () {
            for (var key in this.basicTypeList) {
                this.basicTypeList[key] = ''
            }
        }
    },
    activated: function () {
        this.init()
    }
}
</script>
<style>
.zhengzhuangbuwei .ivu-form-item-required .ivu-form-item-content{margin-left: 0px !important;}
</style>
